# 3.32 Ultrasonic Ranger ## 3.32.1 Overview In this project, we combine the ultrasonic sensor and the OLED module to build a distance meter, whose detection range is 4-300CM. ## 3.32.2 Test Code ### 3.32.2.1 Build Code There are two ways to upload the code: directly open the code file we provide; or manually build blocks. **Directly open the code file we provide:** 1. Click ![](./media/j68.png) and choose `Load from your computer` ![](./media/j67.png) 2. We have already downloaded the codes on computer desktop, so open the file and choose `3-32-rangeFinder.sb3` **Manually build blocks:** 1. Build the two basic blocks:![6-1-4-1-1](./media/6-1-4-1-1.png) 2. Initialize OLED module by ![j53](./media/j53.png) 3. Add a ![j54](./media/j54.png) and set text size to 12x16 4. Declare a variable *distance* and assign the value detected by the ultrasonic sensor to *distance* ![QQ_1722046131988](./media/6-32-2-1-1.png) 5. Add a ![j58](./media/j58.png) to clear the logo displayed on OLED 6. Add an OLED module to display “Distance:” on the first line and show the value of *distance* on the second line. Add the unit of “CM” after the value. 7. At last, add a refresh block. ![QQ_1722046707083](./media/6-32-2-1-2.png) **Complete Test Code** ![6-32-1-2](./media/6-32-1-2.png) ### 3.32.2.2 Test Result After uploading code, “Distance:” will be displayed on the first line. What followed is the distance value in “CM” in the second line. ![6-32-2-2](./media/6-32-2-2.png)